<?php

namespace app\index\model;

use think\Model;
use think\Db;

class Signin extends Model
{
    public function getSignInfo()
    {
        $info = [
            'login'=>false,
            'kiss'=>5,
            'num'=>0,
            'today'=>false
        ];

        if(session('uid')){
            $info['login']=true;

            $signInfo = self::get(['uid'=>session('uid')]);

            if($signInfo && $signInfo->sdate==date("Y-m-d",strtotime('-1 days'))){
                $info['num'] = $signInfo->num;
                $info['kiss'] = $this->getKiss($signInfo->num+1);
            }elseif($signInfo && $signInfo->sdate==date("Y-m-d")){
                $info['num'] = $signInfo->num;
                $info['today'] = true;
                $info['kiss'] = $this->getKiss($signInfo->num);
            }
        }

        return $info;
    }

    public function getKiss($num)
    {
        if($num<5){
            return 5;
        }elseif($num<10){
            return 10;
        }elseif($num<20){
            return 15;
        }else{
            return 20;
        }
    }

}
